/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package polandballgame;
import java.awt.Color;
import java.awt.Graphics;

/**
 * Robot with limited field of view
 * @author POed
 */
public class Polandball extends Countryball {
    
    public int fieldOfView;
    
    int minerals;
    
    @Override public void draw(Graphics context) {
        
        // set field of view
        context.setColor(Color.black);
        context.fillRect(0, 0, Engine.width * Engine.cellSize, Engine.height * Engine.cellSize);
        context.setColor(Color.white);
        int rx, ry, rw, rh;
        rx = (x - fieldOfView + 1) * Engine.cellSize;
        ry = (y - fieldOfView + 1) * Engine.cellSize;
        rw = Math.min((2 * fieldOfView - 1) * Engine.cellSize, Engine.width * Engine.cellSize - rx);
        rh = Math.min((2 * fieldOfView - 1) * Engine.cellSize, Engine.height * Engine.cellSize - ry);
        context.fillRect(rx, ry, rw, rh);
        
        
        if (background != null) {
            background.draw(context);
        }
        
        
        // body:
        context.setColor(Color.black);
        context.drawOval(x * Engine.cellSize, y * Engine.cellSize, Engine.cellSize, Engine.cellSize);
        context.setColor(Color.red);
        context.fillOval(x * Engine.cellSize, y * Engine.cellSize, Engine.cellSize, Engine.cellSize);
        context.setColor(Color.white);
        context.fillArc(x * Engine.cellSize, y * Engine.cellSize, Engine.cellSize, Engine.cellSize, 0, -180);
        // eyes:
        context.fillOval(x * Engine.cellSize + Engine.cellSize / 5, y * Engine.cellSize + Engine.cellSize / 5, Engine.cellSize / 5, Engine.cellSize / 5);
        context.fillOval(x * Engine.cellSize + Engine.cellSize * 3 / 5, y * Engine.cellSize + Engine.cellSize / 5, Engine.cellSize / 5, Engine.cellSize / 5);
    }
    
    public Polandball(int xPos, int yPos) {
        
        super(xPos, yPos);
        
        fieldOfView = 5;
        type = 7;
        
        maxHP = 200;
        currentHP = 100;
        maxArmor = 200;
        currentArmor = 0;
    }
    
    public boolean isObjectVisible(GameObject object) {
        
        return Math.abs(object.y - this.y) < fieldOfView && Math.abs(object.x - this.x) < fieldOfView;
    }
    
    @Override public void grabItem(GameObject item) {
        
        super.grabItem(item);
        
        if (item == null) {
            return;
        }
        
        switch (item.type) {
            
            case 2:
                ++minerals;
                break;
//            case 4:
//                background = item;
//                break;
            default:
                break;
        }
    }
}
